<!--
* description: 战败线索审核-审核(弹窗)
* author: mwh
* createdDate: 2010-11-21
-->
<template>
  <section class="editChangeOwnerAudit">
    <el-dialog v-dialogDrag
      :close-on-click-modal="true"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      @close="sendCode"
      width="1000px"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-params-crm">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === false)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            @emitCode="comp.emitCode"
            :disabled="comp.disabled"
            :isMul="comp.isMul"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :labelName="comp.labelName"
            :inputType="comp.type"
            :lookuptype="comp.lookuptype"
            :dateOptionsType="comp.dateOptionsType"
          ></component>
        </el-row>
      </div>
      <div style="padding:10px 15px;text-align:right;">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import { crmApis } from "@/api/apiList/crm.js";
import { requestGraphQL } from "@/api/commonRequest";
export default {
  // 组件混入对象
  mixins: [formMixins],
     components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: crmApis.clueServerMutationDlrCheck,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.audit("1"),
          text: "同意"
        },
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.audit("0"),
          text: "驳回"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "原销售顾问",
          codeField: "applicant",
          isRequire: false,
          isMust: false,
          disabled: true,
          component: () => import("@/components/crm/textbox/crmTextInput")
        },
        {
          compKey: "compKey2",
          labelName: "划转销售顾问",
          codeField: "applicantId",
          type: "propus",
          isMust: false,
          isMul:false,
          disabled:false,
          component: () => import("@/components/crm/crmEjectWindows/crmSalesConsultant/index"),
          // emitCode:this.applicantChange
        },
        {
          compKey: "compKey3",
          span: 16,
          labelName: "审核意见",
          codeField: "auitOpinion",
          isRequire: true,
          component: () => import("@/components/crm/textbox/crmTextInput"),
          type: "textarea",
          isMust: false
        }
      ],
      // 标题
      textMap: {
        edit: "战败失控线索审核",
        add: "战败失控线索审核"
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        oemCode: this.$store.getters.orgInfo.OEM_CODE,
        groupCode: this.$store.getters.orgInfo.GROUP_CODE,
        applicant: "",
        applicantId:"",
        serverOrder: "",
        crruNode: "",
        auditResult: "",
        auitOpinion: "",
        failRecordCode:"",
      },
      oldApplicantId:""
    };
  },
  mounted(){
    this.oldApplicantId=this.formField.applicantId
  },
  methods: {
    audit(num) {
      debugger;
      let that = this;
      that.$utils.validataMoth(that, "validpopup");
      this.formField.auditResult = num;
      if(!this.formField.applicantId){
        this.formField.applicantId=this.oldApplicantId
      }
      let queryObj = {
        type: "mutation",
        // api配置
        apiConfig: crmApis.clueServerMutationDlrCheck,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: []
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: this.formField
          //   {
          //     applicantId: that.params.applicantId,
          //     serverOrder: that.params.serverOrder,
          //     crruNode: that.params.crruNode,
          //     // serverOrderAndCrruNode: [
          //     //   that.$refs.ClueNumber.input + "&" + that.crruNode
          //     // ],
          //     auditResult: that.form.result,
          //     auitOpinion: that.$refs.CheckThought.input
          //   }
        }
      };
      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestGraphQL(paramD).then(response => {
        if (
          response.data[queryObj.apiConfig.ServiceCode].result == "1" &&
          response.data[queryObj.apiConfig.ServiceCode].rows != ""
        ) {
          that.$notify({
            title: "成功",
            message: "保存成功！",
            type: "success"
          });
          this.$parent.editPopupsVisible = false;
          this.$parent.$refs.multipleTable.queryTable()
        } else {
          that.$notify.error({
            title: "错误",
            message: response.data[queryObj.apiConfig.ServiceCode].msg
          });
        }
      });
    },
    // applicantChange(row){
    //   console.log(row);
    //   this.formField.applicantId=row[0].userId
    // }
  }
};
</script>
